﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_JJFDB_Manager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            PopulateDrop();
        }
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        PopulateJJFD();
    }

    // 删除
    protected void lvDate_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        int KeyID = DongDong.Common.Misc.ConvertToInt(lvDate.DataKeys[e.ItemIndex].Value);
        JJFD.BadDelete(KeyID);
        lvDate.EditIndex = -1;
        PopulateJJFD();
    }

    // 查询
    public void PopulateJJFD()
    {
        lvDate.DataSource = JJFD.GetAllByCondition(DongDong.Common.Misc.ConvertToInt(drpSheng.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpShi.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpQu.SelectedValue), txtAddress.Text, DongDong.Common.Misc.ConvertToInt(drpType.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpSFXYCT.SelectedValue), DongDong.Common.Misc.ConvertToInt(drpIsBM.SelectedValue), txtKFDFS.Text, txtTimeFrom.Text, txtTimeTo.Text);
        lvDate.DataBind();
    }

    // 绑定下拉框
    public void PopulateDrop()
    {
        drpType.PopulateFromEnum<JJFD.typeJJFD>();
        drpType.Items.Insert(0, new ListItem("全部", "999"));
        drpSFXYCT.PopulateFromEnum<JJFD.IsOrNotCT>();
        drpSFXYCT.Items.Insert(0, new ListItem("全部", "999"));
        drpIsBM.PopulateFromEnum<JJFD.IsOrNot>();
        drpIsBM.Items.Insert(0, new ListItem("全部", "999"));

        drpSheng.DataSource = S_Province.GetAll();
        drpSheng.DataValueField = "ProvinceID";
        drpSheng.DataTextField = "ProvinceName";
        drpSheng.DataBind();
        drpSheng.Items.Insert(0, new ListItem("请选择", "0"));

        drpShi.Items.Insert(0, new ListItem("请选择", "0"));

        drpQu.Items.Insert(0, new ListItem("请选择", "0"));
    }

    protected void drpSheng_TextChanged(object sender, EventArgs e)
    {
        int ParentID = DongDong.Common.Misc.ConvertToInt(drpSheng.SelectedValue);
        drpShi.DataSource = S_City.GetAllByCondition(ParentID, "");
        drpShi.DataValueField = "CityID";
        drpShi.DataTextField = "CityName";
        drpShi.DataBind();
        drpShi.Items.Insert(0, new ListItem("请选择", "0"));
    }

    protected void drpShi_TextChanged(object sender, EventArgs e)
    {
        int ParentID = DongDong.Common.Misc.ConvertToInt(drpShi.SelectedValue);
        drpQu.DataSource = S_District.GetAllByCondition(ParentID, "");
        drpQu.DataValueField = "DistrictID";
        drpQu.DataTextField = "DistrictName";
        drpQu.DataBind();
        drpQu.Items.Insert(0, new ListItem("请选择", "0"));
    }

    // 获得省市区名称
    public string GetShengShiName(object sheng, object shi)
    {
        string Return = "暂无资料";
        Return = S_District.GetPName_CNameByPID_CID(sheng, shi);
        return Return;
    }

    // 获得区名称
    public string GetQuName(string qu)
    {
        string Return = "暂无资料";
        Return = S_District.GetQuName(qu).ToString();
        return Return;
    }

    protected void Pager_PreRender(object sender, EventArgs e)
    {
        if (lvDate.Items.Count == 0)
            PopulateJJFD();
    }

    // 获得详细师资基本信息
    public string GetSZJBXX(object ID)
    {
        string Return = "暂无资料";
        Return = "<a target='_blank' href='../../Admin/SZJBXX/DetailManage.aspx?SZID=" + DongDong.Common.Misc.ConvertToInt(ID) + "'>" + ID + "</a>";
        return Return;
    }

    // 获得详细机构基本信息
    public string GetJGJBXX(object ID)
    {
        string Return = "暂无资料";
        Return = "<a target='_blank' href='../../Admin/JGXX/Manage.aspx?JGID=" + DongDong.Common.Misc.ConvertToInt(ID) + "'>" + ID + "</a>";
        return Return;
    }
}